home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gchess40.lha / gnuchess4.0p62 / src / gbookdist.c < prev    next >
C/C++ Source or Header  |  1993-06-22  |  2KB  |  95 lines

  1. #include <fcntl.h>
  2.  
  3. #include "gdbmdefs.h"
  4. #include "gdbmerrno.h"
  5. #include "extern.h"
  6. #include "gnuchess.h"
  7. #undef rxx
  8. #undef cxx
  9. #undef scanz
  10. #undef printz
  11.  
  12. #define rxx "12345678"
  13. #define cxx "abcdefgh"
  14. int nn = 0;
  15.  
  16. int listno = 0;
  17.  
  18. gdbm_file_info *gfd;
  19.  
  20. unsigned bookcount = 0;
  21. unsigned bookup = 0;
  22. unsigned bookmv = 0;
  23.  
  24. union U KEY;
  25. union U DATA;
  26. datum key =
  27. {(char *) NULL, sizeof (union U)};
  28. datum data =
  29. {(char *) NULL, sizeof (union U)};
  30. int temp;
  31. datum return_data;
  32. union U *OB;
  33. struct keydata *OKK;
  34. int i;
  35. int n[N];
  36. char mvstr[6];
  37. void
  38. cvt (f, t)
  39.      unsigned int f, t;
  40. {
  41. /* algebraic notation */
  42.   mvstr[0] = cxx[column (f)];
  43.   mvstr[1] = rxx[row (f)];
  44.   mvstr[2] = cxx[column (t)];
  45.   mvstr[3] = rxx[row (t)];
  46.   mvstr[4] = '\0';
  47. }
  48.  
  49. main (argc,argv)
  50. int argc;
  51. char **argv;
  52. {
  53.   listno=atoi(argv[2]);
  54. printf("%s %d\n",argv[1],listno);
  55.   for (i = 0; i < N; i++) n[i] = 0;
  56.   gfd = gdbm_open (argv[1], 512, GDBM_READER, 00444, NULL);
  57.   nn = temp = 0;
  58.   if (key.dptr != NULL) free (key.dptr);
  59.   return_data = gdbm_firstkey (gfd);
  60.   while (return_data.dptr != NULL)
  61.     {
  62.       OKK = (struct keydata *) return_data.dptr;
  63.       data = gdbm_fetch (gfd, return_data);
  64.       OB = (union U *) data.dptr;
  65.       temp++;
  66.       if(temp%1000 == 0)printf("%d\n",temp);
  67.       if (OB->D.number <= N)
  68.         n[OB->D.number - 1]++;
  69.     if(OKK->bookbd == 0  && OKK->bookkey == 0) nn++;
  70.     
  71.  
  72.  
  73. if(listno){
  74.       printf ("%lx %lx %d ", OKK->bookkey, OKK->bookbd, OKK->side);
  75.       for (i = 0; i < OB->D.number; i++)
  76.         {
  77.           cvt (OB->D.bmove[i] >> 8, OB->D.bmove[i] & 0x3f);
  78.           printf ("%s ", mvstr);
  79.           cvt (OB->D.hint[i] >> 8, OB->D.hint[i] & 0x3f);
  80.           printf ("%s / ", mvstr);
  81.         }
  82.           listno--;
  83.       printf ("\n");
  84. }
  85.       key = return_data;
  86.       free (OB);
  87.       return_data = gdbm_nextkey (gfd, key);
  88.       free (key.dptr);
  89.     }
  90.   printf ("There are %d items in the database.\n\n", temp);
  91.   printf ("%d %d %d %d\n", n[0], n[1], n[2], n[3]);
  92.   printf("nn %d\n",nn);
  93.   key.dptr = NULL;
  94. }
  95.